home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 February: Tool Chest / Dev.CD Feb 94.toast / Tool Chest / Development Platforms / AppsToGo / AppsToGo.src / FontTester / DoEvent.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-18  |  4.6 KB  |  209 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        DoEvent.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1990-1993 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* You may incorporate this sample code into your applications without
  12. ** restriction, though the sample code has been provided "AS IS" and the
  13. ** responsibility for its operation is 100% yours.  However, what you are
  14. ** not permitted to do is to redistribute the source as "DSC Sample Code"
  15. ** after having made changes. If you're going to re-distribute the source,
  16. ** we require that you make it clear in the source that the code was
  17. ** descended from Apple Sample Code, but that you've made changes. */
  18.  
  19.  
  20.  
  21. /*****************************************************************************/
  22.  
  23.  
  24.  
  25. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  26. #include "App.defs.h"        /* Get various application definitions.            */
  27. #include "App.protos.h"        /* Get the prototypes for application.            */
  28.  
  29. #ifndef __CTLHANDLER__
  30. #include "CtlHandler.h"
  31. #endif
  32.  
  33. #ifndef __DESK__
  34. #include <Desk.h>
  35. #endif
  36.  
  37. #ifndef __DISKINIT__
  38. #include <DiskInit.h>
  39. #endif
  40.  
  41. #ifndef __ERRORS__
  42. #include <Errors.h>
  43. #endif
  44.  
  45. #ifndef __MENUS__
  46. #include <Menus.h>
  47. #endif
  48.  
  49. #ifndef __TEXTEDITCONTROL__
  50. #include "TextEditControl.h"
  51. #endif
  52.  
  53. #ifndef __TEXTSERVICES__
  54. #include "TextServices.h"
  55. #endif
  56.  
  57. #ifndef __TOOLUTILS__
  58. #include <ToolUtils.h>
  59. #endif
  60.  
  61. #ifndef __UTILITIES__
  62. #include "Utilities.h"
  63. #endif
  64.  
  65.  
  66.  
  67. /*****************************************************************************/
  68.  
  69.  
  70.  
  71. extern Cursor    *gCursorPtr;    /* See the file Window.c for comments about this global. */
  72.  
  73.  
  74.  
  75. /*****************************************************************************/
  76. /*****************************************************************************/
  77.  
  78.  
  79.  
  80. /* Do the right thing for an event.  Determine what kind of event it is, and
  81. ** call the appropriate routines. */
  82.  
  83. #pragma segment Main
  84. void    DoEvent(EventRecord *event)
  85. {
  86.     WindowPtr    window, oldPort;
  87. /*•••••*/
  88.     FileRecHndl    frHndl;
  89. /*•••••*/
  90.     Point        pt;
  91.     OSErr        err;
  92.     TEHandle    teHndl;
  93.     Rect        rct;
  94.  
  95.     switch(event->what) {
  96.  
  97.         case nullEvent:
  98.             DoIdleTasks(event);
  99.             break;
  100.  
  101.         case mouseDown:
  102.             DoMouseDown(event);
  103.             break;
  104.  
  105.         case autoKey:
  106.         case keyDown:                    /* Check for menukey equivalents. */
  107.             DoKeyDown(event);
  108.             break;
  109.  
  110.         case activateEvt:
  111.             gCursorPtr = nil;            /* Force recalculation of the cursor. */
  112.             DoActivate((WindowPtr)event->message);
  113.             if (TSMTEAvailable()) TSMEvent(event);
  114.             break;
  115.  
  116.         case updateEvt:
  117. /*•••••*/
  118.             DoUpdate(window = (WindowPtr)event->message);
  119.             if (window == GetNextWindow(nil, kDocFileType)) {
  120.                 frHndl = (FileRecHndl)GetWRefCon(window);
  121.                 SetDocSize(frHndl, kwNoChange, (*frHndl)->d.doc.docSize);
  122.             }
  123. /*•••••*/
  124.             break;
  125.  
  126.         case kHighLevelEvent:
  127.             gCursorPtr = nil;            /* Force recalculation of the cursor. */
  128.             DoHighLevelEvent(event);
  129.             break;
  130.  
  131.         case osEvt:
  132.             gCursorPtr = nil;            /* Force recalculation of the cursor. */
  133.             switch ((event->message >> 24) & 0xFF) {
  134.                     /* Must logical and with 0xFF to get only low byte. */
  135.                     /* High byte of message. */
  136.  
  137.                 case mouseMovedMessage:
  138.                     DoIdleTasks(event);
  139.                     break;
  140.  
  141.                 case suspendResumeMessage:
  142.                         /* Suspend/resume is also an activate/deactivate. */
  143.                     gInBackground = !((event->message) & resumeFlag);
  144.                     CTEConvertClipboard((event->message) & convertClipboardFlag, !gInBackground);
  145.                     DoActivate(FrontWindow());
  146.                     HiliteWindows();
  147.                     break;
  148.             }
  149.             break;
  150.  
  151.         case diskEvt:
  152.             gCursorPtr = nil;            /* Force recalculation of the cursor. */
  153.             if (HiWord(event->message) != noErr) {
  154.                 SetPt(&pt, kDILeft, kDITop);
  155.                 err = DIBadMount(pt, event->message);
  156.             }
  157.             break;        /* It is not a bad idea to at least call DIBadMount
  158.                         ** in response to a diskEvt, so that the user can
  159.                         ** format a floppy. */
  160.     }
  161.  
  162.     DoCursor();
  163.     DoAdjustMenus();
  164.  
  165.     if (window = CTETargetInfo(&teHndl, &rct)) {
  166.         if (rct.left < -8192) {
  167.             GetPort(&oldPort);
  168.             SetPort(window);
  169.             SetOrigin(-16384, 0);
  170.             CTEIdle();
  171.             SetOrigin(0, 0);
  172.             SetPort(oldPort);
  173.         }
  174.         else {
  175.             BeginContent(window);
  176.             CTEIdle();
  177.             EndContent(window);
  178.         }
  179.     }
  180. }
  181.  
  182.  
  183.  
  184. /*****************************************************************************/
  185.  
  186.  
  187.  
  188. /* •• Called by DTS.Lib..framework. •• */
  189.  
  190. /* This is called when a window is activated or deactivated. */
  191.  
  192. #pragma segment Main
  193. void    DoActivate(WindowPtr window)
  194. {
  195.     NotifyCancel();
  196.  
  197.     if (IsAppWindow(window)) {
  198.         SetPort(window);
  199.         DoCtlActivate(window);
  200.         DoDrawFrame(window, true);            /* Redraw frame for new activate state. */
  201.         BeginContent(window);
  202.         DoDrawControls(window, true);        /* Redraw content scrollbars for new activate state. */
  203.         EndContent(window);
  204.     }
  205. }
  206.  
  207.  
  208.  
  209.